﻿using System;

namespace Extentions
{
    public static partial class Linq
    {
        /// <summary>
        /// Between or equal to the specified interval.
        /// if (someNumber.Between(3,7)) // Do stuff...
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="obj">The obj.</param>
        /// <param name="lower">The lower.</param>
        /// <param name="upper">The upper.</param>
        /// <returns></returns>
        public static bool BetweenClosed<T>(this T obj, T lower, T upper) where T : IComparable<T>
        {
            return obj.CompareTo(lower) >= 0 && obj.CompareTo(upper) <= 0;
        }

        /// <summary>
        /// Between the specified interval.
        /// if (someNumber.Between(3,7)) // Do stuff...
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="obj">The obj.</param>
        /// <param name="lower">The lower.</param>
        /// <param name="upper">The upper.</param>
        /// <returns></returns>
        public static bool BetweenOpen<T>(this T obj, T lower, T upper) where T : IComparable<T>
        {
            return obj.CompareTo(lower) > 0 && obj.CompareTo(upper) < 0;
        }
    }
}